import cv2
import time
import moud as pm
cap = cv2.VideoCapture(1)
pTime = 0
detector = pm.poseDetector()
while True:
    success, img = cap.read()
    img = detector.findPose(img)
    lmList = detector.findPosition(img) #（img，draw = False)
    if len(lmList) !=0:
        #print(lmList[32])
        cv2.circle(img, (lmList[5][1], lmList[5][2]), 5, (255, 255, 0), cv2.FILLED)#点坐标
        yanx = lmList[2][1] - lmList[5][1]
        yany = lmList[2][2] -lmList[5][2]
        a =lmList[23][1] - lmList[2][1]
        a1=lmList[27][1] - lmList[23][1]

        bi = lmList[0][2]
        shouR = lmList[16][1]
        shouL = lmList[15][1]
        xigaiRx = lmList[26][1]
        xigaiRy = lmList[26][2]
        xigaiLx = lmList[25][1]
        xigaiLy = lmList[26][2]
        jiaoRx = lmList[28][1]
        jiaoRy = lmList[28][2]
        jiaoLx = lmList[27][1]
        jiaoLy = lmList[27][2]
        piRx = lmList[24][1]
        piRy = lmList[24][2]
        piLx = lmList[23][1]
        piLy = lmList[23][2]
        #print('a',a)
        #print('b',a1)
        #quany = (lmList[23][2] - lmList[2][2]) / (lmList[27][2] - lmList[23][2])
        #print('xxxx',quanx)
        #print('yyyy',quany)
        if abs(yanx) < abs(yany) :
            print('有人摔倒')
        if abs(yanx) > abs(yany):
            if a1 == 0:
                print('有人摔倒')
            if abs(xigaiLx - jiaoLx) > abs(xigaiLy - jiaoLy):
                print('有人摔倒')
            if abs(xigaiRx - jiaoRx) > abs(xigaiRy - jiaoRy):
                print('有人摔倒')




    cTime = time.time()#帧率
    fps = 1/(cTime-pTime)
    pTime = cTime

    cv2.putText(img,str(int(fps)),(70,50),cv2.FONT_HERSHEY_PLAIN,3,
                 (255,0,0),3)
    cv2.imshow('Image', img)
    cv2.waitKey(1)
